package com.codeoss.framework.converter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

@Service
public class ConverterStore implements IConverterStore,ApplicationContextAware {
	private static final Logger logger = LoggerFactory.getLogger(ConverterStore.class);
	private ApplicationContext applicationContext;
	@Override
	public IConverter getConverter(String javaType) {
		// TODO Auto-generated method stub
		IConverter converter=(IConverter)applicationContext.getBean(javaType+"Converter");
		if(converter==null && javaType=="timestamp") {
			converter=(IConverter)applicationContext.getBean("datetimeConverter");
		}
		if(converter==null) {
			logger.warn(javaType+"没有对应的Converter");
		}
		return converter;
	}
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		// TODO Auto-generated method stub
		this.applicationContext=applicationContext;
	}
}
